package com.java110.mall.shop.cmd.shopAudit;

import com.alibaba.fastjson.JSONObject;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.mall.shop.bmo.shopAudit.ISaveShopAuditBMO;
import com.java110.po.shop.ShopAuditPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.Assert;
import com.java110.utils.util.BeanConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;

@Java110Cmd(serviceCode = "shopAudit.saveShopAudit")
public class SaveShopAuditCmd extends Cmd {
    @Autowired
    private ISaveShopAuditBMO saveShopAuditBMOImpl;
    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        Assert.hasKeyAndValue(reqJson, "shopId", "请求报文中未包含shopId");
        Assert.hasKeyAndValue(reqJson, "shopLogo", "请求报文中未包含shopLogo");
        Assert.hasKeyAndValue(reqJson, "storeId", "请求报文中未包含storeId");
        Assert.hasKeyAndValue(reqJson, "shopName", "请求报文中未包含shopName");
        Assert.hasKeyAndValue(reqJson, "shopDesc", "请求报文中未包含shopDesc");
        Assert.hasKeyAndValue(reqJson, "mapX", "请求报文中未包含mapX");
        Assert.hasKeyAndValue(reqJson, "mapY", "请求报文中未包含mapY");
        Assert.hasKeyAndValue(reqJson, "sendAddress", "请求报文中未包含sendAddress");
        Assert.hasKeyAndValue(reqJson, "returnAddress", "请求报文中未包含returnAddress");
        Assert.hasKeyAndValue(reqJson, "returnPerson", "请求报文中未包含returnPerson");
        Assert.hasKeyAndValue(reqJson, "returnLink", "请求报文中未包含returnLink");
        Assert.hasKeyAndValue(reqJson, "state", "请求报文中未包含state");
        Assert.hasKeyAndValue(reqJson, "shopType", "请求报文中未包含shopType");
        Assert.hasKeyAndValue(reqJson, "openType", "请求报文中未包含openType");
    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
        ShopAuditPo shopAuditPo = BeanConvertUtil.covertBean(reqJson, ShopAuditPo.class);
        ResponseEntity<String> responseEntity =  saveShopAuditBMOImpl.save(shopAuditPo);
        context.setResponseEntity(responseEntity);
    }
}
